/**
 * 1
 *  
 * @Author : Ruoyu Wang
 * @DateTime : 24-9-18 下午6:53
 */

#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int cost(string s, string tmp) {
    int res = 0;
    for (int i = 0; i < 5; i++) {
        if (s[i] == tmp[i])continue;
        if (tolower(s[i]) == tolower(tmp[i])) {
            res++;
        } else if ((s[i] >= 'a' && s[i] <= 'z' && tmp[i] >= 'a' && tmp[i] <= 'z') ||
                   (s[i] >= 'A' && s[i] <= 'Z' && tmp[i] >= 'A' && tmp[i] <= 'Z')) {
            res++;
        } else {
            res += 2;
        }
    }
    return res;
}

int main() {
    string s;
    string tmp = "AcMer";
    cin >> s;
    int res = 0x3f3f3f3f;
    for (int i = 0; i + 5 <= s.size(); i++) {
        int c = cost(s.substr(i, 5), tmp);
        res = min(res, 5 * c);
        if (res == 0) break;
    }
    cout << res;
    return 0;
}